package com.recSystem.Service.ServiceImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.recSystem.Entity.DO.FavoriteDO;
import com.recSystem.Entity.DTO.PaperDTO;
import com.recSystem.Entity.POJO.HttpResponse;
import com.recSystem.Mapper.FavoriteMapper;
import com.recSystem.Service.FavoriteService;
import com.recSystem.Service.PaperService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class FavoriteServiceImpl extends MPJBaseServiceImpl<FavoriteMapper, FavoriteDO> implements FavoriteService {

    private final PaperService paperService;

    public FavoriteServiceImpl(PaperService paperService) {
        this.paperService = paperService;
    }

    @Override
    public List<FavoriteDO> getFavoriteRelationsByUserId(int userId) {
        return null;
    }

    @Override
    public Page<FavoriteDO> getFavoriteRelationsPageByUserId(int userId, int maxLength, int offset) {
        return null;
    }

    @Override
    public IPage<PaperDTO> getFavoritePapersByPage(int userId, int maxLength, int offset) {
//        IPage<FavoriteDO> pageInfo=new Page<>(offset,maxLength);
//        IPage<FavoriteDO> favorites=baseMapper.selectPage(pageInfo,query().eq("user_id",userId));
//
//        // 得到用户收藏的论文id
//        // List<Integer> paperIds = getFavoriteRelationsByUserId(userId, maxLength, offset);
//        // 根据论文id集合得到论文集合
//        // TODO service层调用service，违背了开发原则
//        return favorites.convert(favoriteDO -> paperService.getPaperDTOById(favoriteDO.getPaperId(),userId));
        return null;
    }

    @Override
    public boolean isFavorite(int userId, int paperId) {
        HashMap<String,Integer> queryMap=new HashMap<>(2);
        queryMap.put("user_id",userId);
        queryMap.put("paper_id",paperId);

        return baseMapper.exists(query().allEq(queryMap));
    }
}
